# coding:utf-8

# from enum import Enum, unique
import wx
import json


# @unique
# class sysLanguage(Enum):
#     # 描述系统操作语言的枚举类型
#     ENS = 0
#     CHN = 1


class Dlg_set_language(wx.Dialog):
    """
    系统操作语言设置窗口
    """
    def __init__(self, parent):
        wx.Dialog.__init__(self, parent=parent, id=-1, title="", pos=wx.DefaultPosition, size=(800, 500))
        self.Center()
        # self.lang = None
        panel = wx.Panel(parent=self, id=-1)
        panel.SetBackgroundColour('lightblue')
        vbox0 = wx.BoxSizer(wx.VERTICAL)

        vbox1 = wx.BoxSizer(wx.VERTICAL)
        font = wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)
        chnlabel = wx.StaticText(parent=panel, id=-1, label="欢迎使用Lemon发酵过程控制系统，请选择语言！")
        chnlabel.SetFont(font)
        vbox1.Add(chnlabel, 1, flag=wx.ALL | wx.ALIGN_CENTER, border=30)
        enslabel = wx.StaticText(parent=panel, id=-1,
                                 label="Welcome to use Lemon fermentation process "
                                       "control system, please select language!")
        enslabel.SetFont(font)
        vbox1.Add(enslabel, 1, flag=wx.LEFT | wx.ALIGN_CENTER, border=30)

        hbox = wx.BoxSizer(wx.HORIZONTAL)
        btnChn = wx.Button(parent=panel, id=-1, label="中文", size=(130, 60))
        btnChn.SetFont(font)
        self.Bind(wx.EVT_BUTTON, self.ChnOnClick, btnChn)
        hbox.Add(btnChn, 1, flag=wx.ALL, border=60)
        btnEns = wx.Button(parent=panel, id=-1, label="English", size=(130, 60))
        btnEns.SetFont(font)
        self.Bind(wx.EVT_BUTTON, self.EnsOnClick, btnEns)
        hbox.Add(btnEns, 1, flag=wx.ALL, border=60)
        vbox0.Add(vbox1, 2, flag=wx.EXPAND | wx.ALL, border=0)
        vbox0.Add(hbox, 1, flag=wx.EXPAND | wx.ALL, border=0)
        panel.SetSizer(vbox0)

    def EnsOnClick(self, event):
        # self.lang = sysLanguage.ENS
        self.EndModal(1)

    def ChnOnClick(self, event):
        # self.lang = sysLanguage.CHN
        self.EndModal(0)


class Cls_ui_text(object):
    def __init__(self):
        object.__init__(self)

    @staticmethod
    def LangConfig(language):
        f = open("./json/text_list.json", "r")
        allTextDict = json.load(f)
        selectTextDict = {}
        for key, value in allTextDict.items():
            if language == 0:
                selectTextDict[key] = value[0]
            elif language == 1:
                selectTextDict[key] = value[1]
        return selectTextDict

def GetLanguage():
    ldlg = Dlg_set_language(None)
    result = ldlg.ShowModal()
    if result == 1 or result == 0:
        return result
    else:
        exit()